package cn.consult.controller.sys.apartment;

import cn.consult.common.api.CommonPage;
import cn.consult.common.api.CommonResult;
import cn.consult.sys.entity.TDwellEmployee;
import cn.consult.sys.entity.TWeEquipment;
import cn.consult.sys.entity.TWeOperatingRecord;
import cn.consult.sys.service.TWeEquipmentService;
import cn.consult.sys.service.TWeOperatingRecordService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

/**
 * @ Author：周xx
 * @ Date：2024-04-09-9:48
 * @ Version：1.0
 * @ Description：水电设备管理
 */
@Api(tags = "公寓管理 > 水电设备管理")
@RestController
@RequestMapping("/apartment/weequipment")
public class TWeEquipmentController {


    @Autowired
    private TWeEquipmentService tWeEquipmentService;
    @Autowired
    private TWeOperatingRecordService tWeOperatingRecordService;


    @ApiOperation("selectPage =>  分页查询水电设备信息")
    @GetMapping("/selectPage")
    public CommonResult selectPage(@RequestParam Map<String, Object> params) {
        IPage<TWeEquipment> page = tWeEquipmentService.selectPage(params);
        return CommonResult.success(CommonPage.restPage(page));
    }


    @GetMapping("/getAll")
    public CommonResult getAll() {
        return CommonResult.success(tWeEquipmentService.list());
    }

    @ApiOperation("deleteWeEquipment =>  删除水电设备信息")
    @DeleteMapping("/deleteWeEquipment/{id}")
    public CommonResult deleteWeEquipment(@PathVariable Long id) {
        boolean save = tWeEquipmentService.removeById(id);
        if (save) {
            return CommonResult.success(save);
        }
        return CommonResult.failed();
    }

    @ApiOperation("addWeEquipment =>  添加水电设备信息")
    @PostMapping("/addWeEquipment")
    public CommonResult addWeEquipment(@RequestBody TWeEquipment tWeEquipment) {
        boolean save = tWeEquipmentService.saveWeEquipment(tWeEquipment);
        if (save) {
            return CommonResult.success(save);
        }
        return CommonResult.failed();
    }

    @ApiOperation("updateWeEquipment =>  修改水电设备信息")
    @PutMapping("/updateWeEquipment")
    public CommonResult updateWeEquipment(@RequestBody TWeEquipment tWeEquipment) {
        boolean update = tWeEquipmentService.updateWeEquipment(tWeEquipment);
        if (update) {
            return CommonResult.success(update);
        }
        return CommonResult.failed();
    }


    @ApiOperation("getOperatingRecord =>  操作记录")
    @GetMapping("/getOperatingRecord")
    public CommonResult getOperatingRecord(@RequestParam Map<String, Object> params) {
        IPage<TWeOperatingRecord> page = tWeOperatingRecordService.getPage(params);
        return CommonResult.success(CommonPage.restPage(page));
    }

    @ApiOperation("getEList =>  电表设备下拉")
    @GetMapping("/getEList")
    public CommonResult getEList() {
        List<TWeEquipment> list = tWeEquipmentService.list(new LambdaQueryWrapper<TWeEquipment>().eq(TWeEquipment::getEquipmentType, "电表"));
        return CommonResult.success(list);
    }

}
